package com.dylearn;

import com.alibaba.druid.pool.DruidDataSource;
import com.dylearn.three.readYml.ReadCommon;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableConfigurationProperties(ReadCommon.class)
//@EnableCaching//启动缓存
//@EnableScheduling//启动定时任务
public class Application {

    @Bean
    @ConfigurationProperties("spring.datasource.druid")
    DruidDataSource druidSource(){
        //第三方bean
        DruidDataSource ds = new DruidDataSource();
        return ds;
    }

    public static void main(String[] args) {

        ConfigurableApplicationContext calc = SpringApplication.run(Application.class, args);

        //yml获取配置文件
        ReadCommon readCommon = calc.getBean(ReadCommon.class);
        System.out.println("readCommon = "+readCommon);

        //获取第三方bean - driver-class-name
        DruidDataSource ds = calc.getBean(DruidDataSource.class);
        System.out.println("ds => " + ds.getDriverClassName());

    }

}
